//
// Created by 紫霄 on 2020/4/14.
//

#ifndef LEETCODE_18_H
#define LEETCODE_18_H
// Definition for singly-linked list.
struct ListNode {
  int val;
  ListNode *next;
  ListNode(int x) : val(x), next(nullptr) {}
};
class Solution {
public:
  ListNode *deleteNode(ListNode *head, int val) {
    if (head->val == val) {
      return head->next;
    }
    ListNode *m = head;
    while (head->next->val != val) {
      head = head->next;
    }
    head->next = head->next->next;
    return head;
  }
};
#endif // LEETCODE_18_H
